/**
 * @file
 * @brief GD32FmwLib：接口
 * @author
 * + 隐星魂 (Roy Sun) <xwos@xwos.tech>
 * @copyright
 * + Copyright © 2015 xwos.tech, All Rights Reserved.
 * > Licensed under the Apache License, Version 2.0 (the "License");
 * > you may not use this file except in compliance with the License.
 * > You may obtain a copy of the License at
 * >
 * >         http://www.apache.org/licenses/LICENSE-2.0
 * >
 * > Unless required by applicable law or agreed to in writing, software
 * > distributed under the License is distributed on an "AS IS" BASIS,
 * > WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * > See the License for the specific language governing permissions and
 * > limitations under the License.
 */

#include "../GD32FmwLib/std.h"
#include <armv7m_isa.h>
#include "../GD32FmwLib/ivt.h"
#include "../GD32FmwLib/mif.h"

extern void SystemInit(void);

/**
 * @brief GD32FMWLIB模块的低级初始化
 * @retrun 错误码
 */
__xwbsp_init_code
void gd32fmwlib_lowlevel_init(void)
{
#if defined(BRDCFG_CM4_DISDEFWBUF) && (1 == BRDCFG_CM4_DISDEFWBUF)
        cm_scs.scnscb.actlr.bit.disdefwbuf = 1;
#endif
}

/**
 * @brief GD32FMWLIB模块的初始化
 * @retrun 错误码
 */
__xwbsp_init_code
void gd32fmwlib_init(void)
{
        SystemInit();
        cm_scs.scb.vtor.u32 = (xwu32_t)&gd32_ivt;
}

/**
 * @brief 启动GD32FMWLIB模块
 * @retrun 错误码
 * @note
 * - 此函数会启动所有外设，有些外设启动流程需要延时，因此此函数只能运行在线程中。
 */
xwer_t gd32fmwlib_start(void)
{
        /* TODO */
        return XWOK;
}

/**
 * @brief 停止GD32FMWLIB模块
 * @retrun 错误码
 * @note
 * - 此函数会停止所有外设，有些外设的停止流程需要延时，因此此函数只能运行在线程中。
 */
xwer_t gd32fmwlib_stop(void)
{
        /* TODO */
        return XWOK;
}
